package com.javaspeak.designpatterns.go4.behavioural.interpreter;

import java.util.List;

/**
 * Typically an interpreted language encapsulates the parsing into
 * different expressions.   In this example all Expressions need to extend
 * AbstractExpression.  In this example we have an InsertExpression and a
 * SelectExpression.
 * <p>
 * The interpreter parses the "Object Query Language (oql) into statements
 * and then checks which expression to use to parse each statement. For
 * example the InsertExpression is used for parsing oql which
 * is inserting data into objects and the SelectExpression is used for parsing
 * oql which is used for retrieving data from objects.
 *
 * @author John Dickerson
 */
public abstract class AbstractExpression {

    /**
     * Classes extending AbstractExpression should pass the oql to parse through
     * their constructor
     *
     * @param context The InterpreterContext which holds a registry of objects.
     *
     * @return return List of Value or null.  The InsertExpression returns null
     * while the SelectExpression returns a list of Value.
     *
     * @throws Exception if oql is not well formed.
     */
    public abstract List<Value> interpret(
            InterpreterContext context ) throws Exception;
}
